package br.com.mural.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.Toast;
import br.com.mural.android.adaptadores.QuestionarioAdapter;
import br.com.mural.android.entidades.Questionario;

public class QuestionarioDetailActivity extends Activity{
	// TextView txtAviso, txtAutor;
	Button btnResponder;
	ListView view;
	
	QuestionarioAdapter adapter;
	Bundle bundle;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_questionario_detail);
		
		bundle = new Bundle();
		
		view = (ListView) findViewById(R.id.lista);
		Bundle dados = getIntent().getExtras();
		Questionario questionario = (Questionario) dados.get("questionario");
		
		btnResponder = (Button) findViewById(R.id.btnResponder);
		
		
		
		adapter = new QuestionarioAdapter(this, questionario.getQuestoes(), bundle);
		
		//view.setClickable(true);
		
		
		view.setAdapter(adapter);
		
		btnResponder.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//Questao q = (Questao) view.getItemAtPosition(view.getCount()-1);
				//view.getAdapter().toString();
				//View v_ = view.fin
				//View view_ = view.getAdapter().
				
				RatingBar ratingBar = ((RatingBar) view.findViewById(R.id.respostaObj));
				
				float rating = ratingBar.getRating();
				
				//Questao questao = questionario.getQuestoes().get(0);
				
				Bundle bundle = adapter.getBundle();
				
				String valor = bundle.getString("1");
				
				//Toast.makeText(getApplicationContext(), "Clicou:"+ , Toast.LENGTH_SHORT).show();
				Toast.makeText(getApplicationContext(), "Clicou:"+ bundle.getString(view.getItemAtPosition(5).toString()), Toast.LENGTH_SHORT).show();
				
			}
		});
		
		
		/*view.setOnItemClickListener(new OnItemClickListener() {  
			  
	        @Override  
	        public void onItemClick(AdapterView<?> adapter, View view,  
	                int position, long id) {  
	        	Toast.makeText(getApplicationContext(), "Clicou:"+ position, Toast.LENGTH_SHORT).show();
	            }  
	          
	    });*/  
		
		
		
		
		
		
		 
		

	}


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.questionario_detail, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}


	


	
}
